package com.neymar.controller;


import com.neymar.entity.Log;
import com.neymar.entity.User;
import com.neymar.service.LogService;
import com.neymar.service.UserService;
import com.neymar.util.RandomID;
import com.neymar.vo.LogVO;
import com.neymar.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 * @author neymar
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/log")
@Api(tags = {"操作日志信息操作接口"})
public class LogController {

    @Autowired
    private LogService logService;

    @ApiOperation("保存日志")
    @PostMapping("/save/{userId}/{operator}/{object}")
    public R save(@PathVariable("userId") String userId,
                  @PathVariable("operator") int operator,
                  @PathVariable("object") int object) {
        int flag = logService.save(userId, operator, object);
        if (flag != 0) {
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("[分页查询]根据用户ID操作日志")
    @GetMapping("/find/{current}/{size}/{userId}")
    public R findLogById(@PathVariable("current") int current, @PathVariable("size") int size,
                         @PathVariable("userId") String userId) {
        return R.ok(logService.findLogByUserId(userId, current, size));
    }

    @ApiOperation("[分页查询]根据时间段查询用户日志")
    @GetMapping("/find/time/{current}/{size}/{startTime}/{endTime}")
    public R findLogByTime(@PathVariable("current") int current, @PathVariable("size") int size,
                           @PathVariable("startTime") Date startTime,
                           @PathVariable("endTime") Date endTime) {
        return R.ok(logService.findLogByTime(startTime, endTime, current, size));
    }

    @ApiOperation("[分页查询]根据所有的操作日志")
    @GetMapping("/findAll/{current}/{size}")
    public R findAllLog(@PathVariable("current") int current, @PathVariable("size") int size) {
        return R.ok(logService.findAllLog(current, size));
    }

    @ApiOperation("操作日志类型统计")
    @GetMapping("/showTypeInfo")
    public R showTypeInfo() {
        return R.ok(logService.showTypeInfo());
    }

}

